<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ JSON.stringify(text) == '{}' ? '添加积分审批节点' : '修改积分审批节点' }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form :form="form">
					<a-form-item label="名称"><a-input v-decorator="['Name', { rules: [{ required: true, message: '请输入名称' }] }]" /></a-form-item>
					<a-form-item label="老师审批">
						<a-radio-group v-decorator="['IsTeacherExam', { rules: [{ required: true, message: '请选择是否老师审批' }] }]">
							<a-radio :value="true">是</a-radio>
							<a-radio :value="false">否</a-radio>
						</a-radio-group>
					</a-form-item>
					<a-form-item label="允许修改">
						<a-radio-group v-decorator="['IsAgreeUpdate', { rules: [{ required: true, message: '请选择是否允许修改' }] }]">
							<a-radio :value="true">是</a-radio>
							<a-radio :value="false">否</a-radio>
						</a-radio-group>
					</a-form-item>
					<!-- <a-form-item label="允许删除">
						<a-radio-group v-decorator="['IsAgreeDelete', { rules: [{ required: true, message: '请选择是否允许删除' }] }]">
							<a-radio :value="true">是</a-radio>
							<a-radio :value="false">否</a-radio>
						</a-radio-group>
					</a-form-item> -->
					<a-form-item class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit">{{ JSON.stringify(text) == '{}' ? '确认添加' : '确认修改' }}</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-item>
				</a-form>
			</div>
		</div>
	</div>
</template>

<script>
import moment from 'moment';
import { ManageClubAnnualAuditFlowTypeDoAdd, ManageClubAnnualAuditFlowTypeDoUpdate } from '@/api/follow';
export default {
	props: {
		text: Object
	},
	watch: {
		text: function(text) {
			let that = this;
			if (JSON.stringify(text) == '{}') {
				that.currentID = ''
				setTimeout(function() {
					that.form.setFieldsValue({
						IsTeacherExam: false,
						IsAgreeUpdate: false,
						IsAgreeDelete:false
					});
				},300)
			} else {
				that.currentID = text.ID;
				console.log(text)
				setTimeout(function() {
					for (let i in text) {
						that.form.setFieldsValue({
							[i]: text[i]
						});
					}
				}, 300);
			}
		}
	},
	data() {
		return {
			loading: false,
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			}),
			currentID: '',
			UserList: []
		};
	},
	created() {},
	methods: {
		moment,
		closeFunction(data) {
			this.form.resetFields();
			this.$emit('closeFun', data);
		},
		handleSubmit(e) {
			this.form.validateFields(async (err, values) => {
				if (!err) {
					let data = {};
					data = values;
					let res = {};
					if (!this.currentID) {
						res = await ManageClubAnnualAuditFlowTypeDoAdd(data);
					} else {
						data.id = this.currentID;
						res = await ManageClubAnnualAuditFlowTypeDoUpdate(data);
					}
					if (res.data.code === 0) {
						this.$message.success(res.data.msg);
						this.closeFunction('1');
					} else {
						this.$message.error(res.data.msg);
					}
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
/deep/.ant-form {
	margin-top: 50px;
	padding-bottom: 50px;
}
/deep/.ant-form-item {
	margin: 20px 50px;
	display: flex;
}
/deep/.ant-form-item-label {
	width: 100px;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: right;
}
/deep/.ant-form-item-control-wrapper {
	flex: 1;
}
/deep/.ant-calendar-picker {
	width: 100% !important;
}
.ant-upload-list-picture-card-container {
	width: 80px;
	height: 80px;
}
</style>
